package top.laoshuzi.designpatterns.base.behavior.iterator;

/**
 * 具体集合
 */
public class ConcreteContainer implements Container {


    private Object[] objects;

    public ConcreteContainer(Object[] objects) {
        this.objects = objects;
    }

    @Override
    public Iterator iterator() {
        return new ConcreteIterator();
    }

    private class ConcreteIterator implements Iterator {

        private int index;

        @Override
        public boolean hasNext() {
            if (index < objects.length) {
                return true;
            }
            return false;
        }

        @Override
        public Object next() {
            if (this.hasNext()) {
                return objects[index++];
            }
            return null;
        }
    }
}
